package com.storage.web.controller.system;

import com.storage.common.annotation.Log;
import com.storage.common.core.controller.BaseController;
import com.storage.common.core.domain.AjaxResult;
import com.storage.common.core.domain.ServiceResponse;
import com.storage.common.core.page.TableDataInfo;
import com.storage.common.enums.BusinessType;
import com.storage.framework.web.OperationContext;
import com.storage.framework.web.enums.RequestOperation;
import com.storage.system.domain.StorageShop;
import com.storage.system.service.IStorageShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺 信息操作处理
 *
 * @author storage
 * @date 2019-08-18
 */
@Api(tags = "店铺相关接口")
@RestController
public class StorageShopController extends BaseController {

    @Autowired
    private IStorageShopService storageShopService;

    /**
     * 查询店铺列表
     */
    @ApiOperation(value = "查询店铺列表")
    @GetMapping("/system/storageShop/list")
    @ResponseBody
    public TableDataInfo list(@RequestOperation OperationContext context,
                              StorageShop storageShop, Integer pageNum, Integer pageSize) {
        ServiceResponse<TableDataInfo> response = storageShopService.selectStorageShopList(context.getStorageUser(), storageShop, pageNum, pageSize);
        return response.getData();
    }

    /**
     * 新增保存店铺
     */
    @ApiOperation(value = "新增保存店铺")
    @Log(title = "店铺", businessType = BusinessType.INSERT)
    @PostMapping("/system/storageShop/add")
    @ResponseBody
    public AjaxResult addSave(@RequestOperation OperationContext context,
                              @RequestBody StorageShop storageShop) {
        return storageShopService.insertStorageShop(context.getStorageUser(), storageShop);
    }

    /**
     * 修改保存店铺
     */
    @ApiOperation(value = "修改保存店铺")
    @Log(title = "店铺", businessType = BusinessType.UPDATE)
    @PostMapping("/system/storageShop/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestOperation OperationContext context,
                               @RequestBody StorageShop storageShop) {
        return storageShopService.updateStorageShop(context.getStorageUser(), storageShop);
    }

    /**
     * 删除店铺
     */
    @ApiOperation(value = "删除店铺")
    @Log(title = "店铺", businessType = BusinessType.DELETE)
    @GetMapping("/system/storageShop/remove")
    @ResponseBody
    public AjaxResult remove(@RequestParam("ids") String ids) {
        ServiceResponse<Boolean> response = storageShopService.deleteStorageShopByIds(ids);
        if (!response.isSuccess()) {
            return AjaxResult.error(response.getError());
        }
        return AjaxResult.success();
    }

    // 5.店铺销售列表，查询出所有货号，并显示当前货号卖出的双数，多的排在前面

    /**
     * 查询店铺销售订单列表
     */
    @ApiOperation(value = "查询店铺销售订单列表")
    @GetMapping("/system/hop/sell/orders")
    @ResponseBody
    public TableDataInfo shopOrderList(@RequestOperation OperationContext context,
                                       StorageShop storageShop, Integer pageNum, Integer pageSize) {
        ServiceResponse<TableDataInfo> response = storageShopService.queryShopSellOrders(context.getStorageUser(), storageShop, pageNum, pageSize);

        return response.getData();
    }

}
